package test;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * @author zhu
 * @date 2024-03-26
 */
public class MainTest05 {
    public static void main(String[] args) throws Exception {
        Class<Scanner> clazz = Scanner.class;

        Constructor<Scanner> constructor = clazz.getConstructor(InputStream.class);
        Scanner scanner = constructor.newInstance(System.in);
        Method nextIntMethod = clazz.getMethod("nextInt");
        System.out.println("请输入年份：");
        Object obj = nextIntMethod.invoke(scanner);

        // 判断闰年或平年
        if (obj instanceof Integer){
            if (((int)obj % 4 == 0 && (int)obj % 100 != 0) || (int)obj % 400 == 0) {
                System.out.println(obj + " 是闰年。");
            } else {
                System.out.println(obj + " 是平年。");
            }
        }

    }
}
